<?php
    include 'base.php';

    // 定义字段
    $username = $_POST['username'];
    $password = $_POST['password'];

    // SQL语句
    $sql = "SELECT * FROM `user` WHERE `username`='$username' AND `password`='$password'";

    // 执行SQL
    $res = $conn->query($sql);

    // 查到返回一条数据
    $row = mysqli_fetch_assoc($res);

    if ($row) {
        // 成功
        echo json_encode(Array(
            'code' => 0,
            'msg' => '登陆成功',
            'token' => 'asdfasasd4534asd53453sd1'
            // 'username' => '$username'
        ));
    } else {
        // 失败
        echo json_encode(Array(
            'code' => 1,
            'msg' => '登陆失败',
            'token' => ''
            // 'username'  => ''
        ));
    }
?>